<?php

namespace Remoteshell\PhpBotSdk\logger;

/**
 * Class STDLoggerOut
 * @package Remoteshell\PhpBotSdk\logger
 * 标准日志输出
 * 将内容输出到控制台上并记录
 */
class STDLoggerOut extends LoggerRecoder
{
    private const COLORS = [
        "normal" => "\033[0;32m", // 绿色
        "error" => "\033[0;31m",  // 红色
        "warning" => "\033[0;33m", // 黄色
        "alert" => "\033[0;35m",  // 紫色
        "critical" => "\033[0;31m", // 红色
        "emergency" => "\033[0;31m", // 红色
        "notice" => "\033[0;36m", // 青色
    ];

    public function record(string $mode, string $message): void
    {
        $color = self::COLORS[$mode] ?? self::COLORS["normal"];
        $reset = "\033[0m";

        switch ($mode) {
            case "normal":
                LoggerRecoder::getLog()->info($message);
                echo $color . "[INFO] " . $message . $reset . "\n";
                break;
            case "error":
                LoggerRecoder::getLog()->error($message);
                echo $color . "[ERROR] " . $message . $reset . "\n";
                break;
            case "warning":
                LoggerRecoder::getLog()->warning($message);
                echo $color . "[WARN] " . $message . $reset . "\n";
                break;
            case "alert":
                LoggerRecoder::getLog()->alert($message);
                echo $color . "[ALERT] " . $message . $reset . "\n";
                break;
            case "critical":
                LoggerRecoder::getLog()->critical($message);
                echo $color . "[CRITICAL] " . $message . $reset . "\n";
                break;
            case "emergency":
                LoggerRecoder::getLog()->emergency($message);
                echo $color . "[EMERGENCY] " . $message . $reset . "\n";
                break;
            case "notice":
                LoggerRecoder::getLog()->notice($message);
                echo $color . "[NOTICE] " . $message . $reset . "\n";
                break;
            default:
                LoggerRecoder::getLog()->info($message);
                echo $color . "[INFO] " . $message . $reset . "\n";
                break;
        }
    }
}
